/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pfc.comun;

import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.tree.TreeModel;

/**
 *
 * @author xandru
 */
public class Proyecto {

    public String nombre;
    public String path;
    private String appsFolder;
    private String srcFolderName = "src";
    private String buildFolderName = "build";
    private String  distFolderName =  "dist";
    private String  webFolderName = "web";
    private final String dsFile;
    private final String dbModelFile;
    private final String entityModelFile;
    private final String codeGenerationFile;

    public Proyecto(String nombre, String path) {
        this.nombre = nombre;
        this.path = path;
        this.appsFolder = path + File.separator + "apps";

        dsFile = path + File.separator + "db" + File.separator + nombre + "-ds.properties";
        dbModelFile = path + File.separator + "db" + File.separator + "dbmodel-base.xml";
        entityModelFile = path + File.separator + "db" + File.separator + "ermodel.xml";
        codeGenerationFile =  path + File.separator +  "cgmodel.xml";

        System.out.println("Creado proyecto nombre=" + nombre + " path=" + path);
    }

    public String getDSFilePath()
    {
        return dsFile;
    }

    boolean load (File fichero)
    {
        System.out.println("Cargando " + fichero);
        return true;
    }

    public int  crearNuevo() {
        path = path.replaceAll("\\\\", "/");
        File dir = new File(path);
        File projectDir = new File(path);

        File projectConf = new File(path + File.separator + nombre + ".xml" );
        File db = new File(projectDir.getAbsolutePath() + File.separator + "db");
        int resultado=-1;

        try {
            System.out.println("Creando directorio " +path + " ");
            resultado = 0;
            
            boolean ok1 = projectDir.mkdir();
            db.mkdirs();
          
            boolean ok2 = projectConf.createNewFile();
            if ((!ok1)&&(!ok2))
                resultado = Errores.ERROR_PROYECTO_YA_EXISTE;
            
        } catch (Exception ex) {
           System.out.println(ex.getMessage());
           resultado = Errores.ERROR_PROYECTO_YA_EXISTE;
        }
        finally {
            return resultado;
        }
    }

    void addAlArbol(TreeModel model) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public String getAppsFolder() {
        return appsFolder;
    }

    public void setAppsFolder(String appsFolder) {
        this.appsFolder = appsFolder;
    }

    public String getBuildFolderName() {
        return buildFolderName;
    }

    public String getDistFolderName() {
        return distFolderName;
    }

    public String getNombre() {
        return nombre;
    }

    public String getPath() {
        return path;
    }

    public String getSrcFolderName() {
        return srcFolderName;
    }

    public String getWebFolderName() {
        return webFolderName;
    }



}
